<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
 <TITLE>The VFLib Graph Matching Library, version 2.0: Using VFLib: a quick tour : Building a graph</TITLE>
 <LINK HREF="vflib-7.html" REL=next>
 <LINK HREF="vflib-5.html" REL=previous>
 <LINK HREF="vflib.html#toc3" REL=contents>
</HEAD>
<BODY>
<A HREF="vflib-7.html">Next</A>
<A HREF="vflib-5.html">Previous</A>
<A HREF="vflib.html#toc3">Contents</A>
<HR>
<H2>3.1 Building a graph</H2>

<P>The main difficulty is that in order to make the graph representation
compact and efficient, we have chosen a data structure which is not
modifiable. Once you constructs a graph, you cannot change it
(except for the node/edge attributes) without building a new
graph.
<P>As a consequence, the creation of the graph must be split into
two phases: in the first you must create an instance of the
class <CODE>ARGLoader</CODE>, which gathers all the information needed
to build the graph (for instance, by loading data from
a file), and then in the second phase you create an instance of the
class <CODE>Graph</CODE>, passing the <CODE>ARGLoader</CODE> to its constructor,
in order to actually build the graph. Both <CODE>Graph</CODE> and
<CODE>ARGLoader</CODE> are declared in the include file <CODE>argraph.h</CODE> .
<P><CODE>ARGLoader</CODE> is an abstract class, from which the user should 
derive its own loader class to implement the desired way to
load or to generate the graphs. In VFLib we have provided 
some simple implementations of <CODE>ARGLoader</CODE> to perform
generation and loading of graphs using a not very sophisticated 
file format.
<P>One of these classes is <CODE>ARGEdit</CODE>, declared in <CODE>argedit.h</CODE> ,
which implements some simple graph editing operations. For instance,
the user may generate the graph by successive node and edge
insertions, and then use the <CODE>ARGEdit</CODE> to initialize a <CODE>Graph</CODE>
object. 
<P>
<P>For example, suppose you want to generate a complete 4 nodes graph.
You have first to create an <CODE>ARGEdit</CODE>, then you have to insert the
four nodes, and finally for each pair of nodes you have to insert the
corresponding edge. The code performing this operation would be:
<P>
<BLOCKQUOTE><CODE>
<HR>
<PRE>
#include "argraph.h"
#include "argedit.h"

int main()
  { ARGEdit ed;  // The object used to create the graph
    int i,j;

        // Insert the four nodes
        for(i=0; i&lt;4; i++)
          ed.InsertNode(NULL); // The inserted node will have index i.
                               // NULL stands for no semantic attribute.

        // Insert the edges
        for(i=0; i&lt;4; i++)
          for(j=0; j&lt;4; j++)
            if (i!=j)
                  ed.InsertEdge(i, j, NULL); // NULL stands for no sem. attribute.

        
        // Now the Graph can be constructed...
        Graph g(&amp;ed);

        // To be continued...
</PRE>
<HR>
</CODE></BLOCKQUOTE>

In a later subsection, some other <CODE>ARGLoader</CODE> implementations
will be presented which can be used to load a graph from a 
file.
<P>
<P>
<HR>
<A HREF="vflib-7.html">Next</A>
<A HREF="vflib-5.html">Previous</A>
<A HREF="vflib.html#toc3">Contents</A>
</BODY>
</HTML>
